@ write.S: write sycall wrapper
@
@ Authors: Nora Tarano   ntarano@andrew.cmu.edu
@          Yuan Meng     yuanm@andrew.cmu.edu
@          Yipeng Yun    yipengy@andrew.cmu.edu
@ Date:    Sat Oct 15, 2011

#include <bits/swi.h>
#include <bits/fileno.h>
#include <bits/errno.h>

	.file	"write.S"
	.text

	.extern	errno

	.global	write
write:
	swi	WRITE_SWI	@ system call to write
	movs	r6, r0	@ make copy of return value
	bmi	set_errno	@ if ret < 0, set errno appropriately
	b	write_end

set_errno:
	rsb	r6, r6, #0
	ldr	r7, =errno
	str	r6, [r7]	@ errno = abs(ret)
	mov	r0, #-1		@ set r0 = -1 (error)

write_end:
	mov	pc, lr
